{extend name="public:layout" /}
{block name="title"}区域列表{/block}
{block name="head"}
<style type="text/css">
    .col-sm-4{font-size:14px;}
    .input-sort{
        width:40px;padding:0 8px;color:#777;background:#fff;
        border:1px solid #D9D9D9;border-top-color:#c0c0c0;
    }
</style>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 栏目列表</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <div class="pull-left">
                    <form class="form-inline">
                        <div class="form-group">
                            <label>区域名称</label>
                            <input type="text" class="form-control" name="area_name" />
                        </div>
                        <button type="button" id="btnAdd" class="btn btn-primary">新增</button>
                    </form>
                </div>
                <div class="pull-right">
                    <a class="btn btn-primary" href="{:url('updateCache')}">
                        <i class="fa"></i>&nbsp;更新缓存
                    </a>
                    {gt name="Request.param.pid" value="0"}
                    <a href="javascript:;" onclick="back();" class="btn btn-info">返回上一级</a>
                    {/gt}
                    <a href="{:url('createjs')}" class="btn btn-white">同步级联js</a>
                    <button type="button" id="btnOrder" class="btn btn-white">更新排序</button>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="row">
                {volist name="area" id="vo"}
                <div class="col-sm-4" style="margin-bottom:8px;">
                    <input name="sort[{$vo.id}]" class="input-sort" value="{$vo.area_sort}" style="width:40px;" />
                    {$vo.area_name}
                    <a href="{:url('index',['pid'=>$vo['id']])}">管理</a>
                    <a href="javascript:;" onclick="doAction(this);"
                       data-msg="确认删除吗？" data-url="{:url('del')}" data-params="id={$vo.id}">
                        删除</a>
                </div>
                {/volist}
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function(){
        $('#btnAdd').bind('click',function(){
            var area_name = $("input[name='area_name']").val();
            var pid = "{$Request.param.pid}";
            var url = "{:url('add')}";
            if(area_name==''){
                top.layer.alert('请填写区域名称！');
                return false;
            }
            if(pid=='') pid=0;
            getAjax(url,{pid:pid,area_name:area_name},function (data) {
                rePage();
            });
        });
        $('#btnOrder').bind('click',function () {
            var params = $(".input-sort").serialize();
            var url = "{:url('upOrder')}";
            getAjax(url, params, function (data) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 800}, function () {
                        rePage();
                    });
                }
            });
        })
    })
</script>
{/block}